package com.ruoyi.web.controller.memberCoupon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StoredValueCardRule;
import com.ruoyi.system.service.IStoredValueCardRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 储值卡规则 Controller
 *
 * @author ruoyi
 * @date 2025-05-22
 */
@Api(tags="储值卡规则")
@RestController
@RequestMapping("/system/storedValueCardRule")
public class StoredValueCardRuleController extends BaseController
{
    @Autowired
    private IStoredValueCardRuleService storedValueCardRuleService;

    /**
     * 通过门店名称查询储值卡规则列表
     */
    @ApiOperation("通过门店名称查询储值卡规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName) {
        startPage();
        List<StoredValueCardRule> list = storedValueCardRuleService.selectStoredValueCardRuleListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出储值卡规则列表
     */
    @ApiOperation("导出储值卡规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "储值卡规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<StoredValueCardRule> list = storedValueCardRuleService.selectStoredValueCardRuleListByName(storeName);
        ExcelUtil<StoredValueCardRule> util = new ExcelUtil<StoredValueCardRule>(StoredValueCardRule.class);
        util.exportExcel(response, list, "储值卡规则数据");
    }

    /**
     * 通过id获取储值卡规则详细信息
     */
    @ApiOperation("通过id获取储值卡规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storedValueCardRuleService.selectStoredValueCardRuleById(id));
    }

    /**
     * 新增储值卡规则
     */
    @ApiOperation("新增储值卡规则")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "储值卡规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoredValueCardRule storedValueCardRule)
    {
        return toAjax(storedValueCardRuleService.insertStoredValueCardRule(storedValueCardRule));
    }

    /**
     * 修改储值卡规则
     */
    @ApiOperation("修改储值卡规则")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "储值卡规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoredValueCardRule storedValueCardRule)
    {
        return toAjax(storedValueCardRuleService.updateStoredValueCardRule(storedValueCardRule));
    }

    /**
     * 通过id批量删除储值卡规则信息
     */
    @ApiOperation("通过id批量删除储值卡规则信息")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "储值卡规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storedValueCardRuleService.deleteStoredValueCardRuleByIds(ids));
    }
}
